home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
comms
/
other
/
slrn
/
slrn_src
/
src
/
misc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-05-14
|
39KB
|
1,915 lines
/* -*- mode: C; mode: fold; -*- */
/* Copyright (c) 1998 John E. Davis (davis@space.mit.edu)
*
* This file is part of slrn.
*
* Slrn is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* Slrn is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with Slrn; see the file COPYING. If not, write to the Free
* Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "slrnfeat.h"
/*{{{ Include Files */
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <ctype.h>
#include <errno.h>
#include <time.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#if !defined(VMS) && !defined(__WIN32__) && !defined(__NT__)
# define HAS_PASSWORD_CODE 1
# include <pwd.h>
#endif
#ifdef VMS
# include "vms.h"
#else
# include <sys/types.h>
# include <sys/stat.h>
#endif
#if defined(VMS) && defined(MULTINET)
# include "multinet_root:[multinet.include]netdb.h"
#else
# if defined(__NT__)
# include <winsock.h>
# else
# if defined(__WIN32__)
# define Win32_Winsock
# include <windows.h>
# else
# include <netdb.h>
# ifndef h_errno
extern int h_errno;
# endif
# endif
# endif
#endif
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#ifdef NeXT
# undef WIFEXITED
# undef WEXITSTATUS
#endif
#ifndef WEXITSTATUS
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
#endif
#ifndef WIFEXITED
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
#endif
#include <slang.h>
#include "jdmacros.h"
#include "misc.h"
#include "group.h"
#include "slrn.h"
#include "post.h"
#include "server.h"
#include "util.h"
#include "ttymsg.h"
#include "chmap.h"
#if SLRN_HAS_MIME
#include "mime.h"
#endif
#ifdef VMS
/* valid filname chars for unix equiv of vms filename */
# define VALID_FILENAME_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_-/"
# include "vms.h"
#endif
/*}}}*/
/*{{{ Global Variables */
int Slrn_Full_Screen_Update = 1;
int Slrn_User_Wants_Confirmation = 1;
int Slrn_Message_Present = 0;
int Slrn_Abort_Unmodified = 0;
#ifndef VMS
char *Slrn_SendMail_Command;
#endif
char *Slrn_Editor;
char *Slrn_Editor_Post;
char *Slrn_Editor_Score;
char *Slrn_Editor_Mail;
Slrn_User_Info_Type Slrn_User_Info;
SLKeyMap_List_Type *Slrn_RLine_Keymap;
/*}}}*/
/*{{{ Static Variables */
static int Error_Present;
static SLang_RLine_Info_Type *Slrn_Keymap_RLI;
static char *Input_String;
static char *Input_String_Ptr;
static char *Input_Chars_Ptr;
static char *Input_Chars;
static int Beep_Pending;
/*}}}*/
static void redraw_message (void);
static void redraw_mini_buffer (void);
/*{{{ Screen Update Functions */
void slrn_smg_refresh (void)
{
if (Slrn_TT_Initialized & SLRN_SMG_INIT)
{
slrn_push_suspension (0);
if (Beep_Pending)
SLtt_beep ();
Beep_Pending = 0;
SLsmg_refresh ();
slrn_pop_suspension ();
}
}
void slrn_set_color (int color) /*{{{*/
{
SLsmg_set_color (color);
}
/*}}}*/
void slrn_redraw (void) /*{{{*/
{
if (Slrn_Batch) return;
slrn_push_suspension (0);
SLsmg_cls ();
Slrn_Full_Screen_Update = 1;
redraw_message ();
slrn_update_screen ();
redraw_mini_buffer ();
slrn_smg_refresh ();
slrn_pop_suspension ();
}
/*}}}*/
void slrn_print_percent (int row, int col, SLscroll_Window_Type *w) /*{{{*/
{
int bot_showing;
unsigned int bot_number;
SLsmg_erase_eol ();
SLsmg_gotorc (row, col);
SLsmg_printf ("-- %d/%d", w->line_num, w->num_lines);
bot_number = w->line_num + (w->nrows - w->window_row) - 1;
bot_showing = ((w->bot_window_line == NULL)
|| (w->num_lines == bot_number));
if (w->line_num == w->window_row + 1)
{
SLsmg_write_string (bot_showing ? " (All)" : " (Top)" );
}
else if (bot_showing) SLsmg_write_string(" (Bot)");
else SLsmg_printf(" (%d%%)", (100 * bot_number) / w->num_lines);
SLsmg_erase_eol ();
}
/*}}}*/
void slrn_update_top_status_line (void) /*{{{*/
{
if (Slrn_Full_Screen_Update == 0) return;
SLsmg_gotorc (0, 0);
slrn_set_color (MENU_COLOR);
SLsmg_printf ("\
slrn %s ** Press '?' for help, 'q' to quit. ** Server: %s",
Slrn_Version,
Slrn_Server_Obj->sv_name);
SLsmg_erase_eol ();
slrn_set_color (0);
}
/*}}}*/
/*}}}*/
/*{{{ Message/Error Functions */
/* The first character is the color */
static char Message_Buffer[1024];
static void redraw_message (void)
{
int color;
char *m, *mmax;
if (Slrn_Batch) return;
if (Slrn_Message_Present == 0)
return;
slrn_push_suspension (0);
SLsmg_gotorc (SLtt_Screen_Rows - 1, 0);
color = Message_Buffer [0];
m = Message_Buffer + 1;
while (1)
{
mmax = slrn_strchr (m, 1);
if (mmax == NULL)
mmax = m + strlen(m);
slrn_set_color (color);
SLsmg_write_nchars (m, (unsigned int) (mmax - m));
if (*mmax == 0)
break;
mmax++;
if (*mmax == 0)
break;
slrn_set_color (RESPONSE_CHAR_COLOR);
SLsmg_write_nchars (mmax, 1);
m = mmax + 1;
}
SLsmg_erase_eol ();
slrn_set_color (0);
slrn_pop_suspension ();
}
static void vmessage_1 (int color, char *fmt, va_list ap)
{
vsprintf (Message_Buffer + 1, fmt, ap);
Message_Buffer[0] = (char) color;
Slrn_Message_Present = 1;
redraw_message ();
}
static void vmessage (FILE *fp, char *fmt, va_list ap)
{
if (Slrn_TT_Initialized & SLRN_SMG_INIT)
vmessage_1 (0, fmt, ap);
else
slrn_tty_vmessage (fp, fmt, ap);
}
static void verror (char *fmt, va_list ap)
{
if ((Slrn_TT_Initialized & SLRN_SMG_INIT) == 0)
{
slrn_tty_vmessage (stderr, fmt, ap);
}
else if (Error_Present == 0)
{
slrn_clear_message ();
Error_Present = 1;
Beep_Pending = 1;
vmessage_1 (ERROR_COLOR, fmt, ap);
SLang_flush_input ();
}
if (SLang_Error == 0) SLang_Error = INTRINSIC_ERROR;
}
/*}}}*/
void slrn_clear_message (void) /*{{{*/
{
Slrn_Message_Present = Error_Present = 0;
/* SLang_Error = 0; */
Beep_Pending = 0;
SLKeyBoard_Quit = 0;
if ((Slrn_TT_Initialized & SLRN_SMG_INIT) == 0)
return;
slrn_push_suspension (0);
SLsmg_gotorc (SLtt_Screen_Rows - 1, 0);
SLsmg_erase_eol ();
*Message_Buffer = 0;
slrn_pop_suspension ();
}
/*}}}*/
void slrn_va_message (char *fmt, va_list ap)
{
if (Error_Present == 0)
vmessage (stderr, fmt, ap);
}
int slrn_message (char *fmt, ...) /*{{{*/
{
va_list ap;
if (Error_Present) return -1;
va_start(ap, fmt);
vmessage (stdout, fmt, ap);
va_end (ap);
return 0;
}
/*}}}*/
int slrn_message_now (char *fmt, ...) /*{{{*/
{
va_list ap;
if (Error_Present) return -1;
va_start(ap, fmt);
vmessage (stdout, fmt, ap);
va_end (ap);
slrn_smg_refresh ();
Slrn_Message_Present = 0;
return 0;
}
/*}}}*/
void slrn_error (char *fmt, ...) /*{{{*/
{
va_list ap;
va_start(ap, fmt);
verror (fmt, ap);
va_end (ap);
}
/*}}}*/
void slrn_error_now (unsigned secs, char *fmt, ...) /*{{{*/
{
va_list ap;
if (fmt != NULL)
{
va_start(ap, fmt);
verror (fmt, ap);
va_end (ap);
}
slrn_smg_refresh ();
Slrn_Message_Present = 0;
if (secs) sleep (secs);
}
/*}}}*/
int slrn_check_batch (void)
{
if (Slrn_Batch == 0) return 0;
slrn_error ("This function is not available in batch mode.");
return -1;
}
/*}}}*/
/*{{{ File Related Functions */
#ifdef VMS
/*{{{ VMS Filename fixup functions */
static void vms_fix_name(char *name)
{
int idx, pos;
pos = strspn(name, VALID_FILENAME_CHARS);
if (pos == strlen(name))
return;
for(idx=pos;idx<strlen(name);idx++)
if (!(isdigit(name[idx]) || isalpha(name[idx]) || (name[idx] == '$') || (name[idx] == '_') || (name[idx] == '-')
|| (name[idx] =